package cloud.lysky.order.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.UUID;

@Slf4j
@Configuration
public class FeignInterceptorConfig {

    @Bean
    public RequestInterceptor requestInterceptor() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                // 记录请求信息
                log.info("Sending request to {} with headers: {}", requestTemplate.url(), requestTemplate.headers());
                // 添加自定义请求头
                requestTemplate.header("X-Custom-Header", UUID.randomUUID().toString());
                // 添加认证信息
                requestTemplate.header("Authorization", "我的专用领牌");
                // 还可以访问和修改请求体、查询参数等

            }
        };
    }
}
